<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tfFormbutton
 *
 * @author wlf
 */

if(!defined('TinyFW')) exit('Access denied!');

class tfFormbutton extends tfFormElement {

    private $_type;

    public function  __construct( $type='button', $name = '', $id='' , $caption = '', $value = "", $attr_array = '' ) {
        $this->setCaption($caption);
        $this->setName($name);
        $this->setId($id);
        $this->setValue($value);
        $this->_set_type($type);

        if(!empty($attr_array)) {
            $this->setAttr($attr_array);
        }
        
    }


    private function _set_type($type) {
        $type = strtolower($type);
        $this->_type = in_array($type,array('button','submit','reset')) ? $type : "button";
        /*
        if(in_array(strtolower($type),array('button','submit','reset'))) {
            $this->_type = $type;
        } else {
            $this->_type = 'button';
        }
        */
    }

    public function getType() {
        //return in_array(strtolower($this->_type), array('button','submit','reset')) ? $this->_type : "button";
        return $this->_type;
    }

    public function render() {
        return "<input type='" . $this->getType() . "' name='" . $this->getName() . "' id='" . $this->getId() . "' value='" . $this->getValue() . "' " . $this->getAttrStr() . "  />";
    }

    /*
    public function  __toString() {
        return $this->render();
    }
    */
    
}
?>
